﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moq;
using HRCIS.SchemaLoader;
using HRC.Library.DBAccessLayer;

namespace HRCIS.Tests
{
    [TestFixture]
    public class SchemaLoaderTests
    {
        #region Init and tear down
        [TestFixtureSetUp]
        public void Init()
        {
            Tools.DropCreateTable();
        }

        //[TestFixtureTearDown]
        public void KillThemAll()
        {
            Tools.DropTable();
        }
        #endregion

        [Test, Ignore]
        public void GetTableList_Should_Be_Properly_Working()
        {
            HRCIS.SchemaLoader.SchemaLoader loader = new HRCIS.SchemaLoader.SchemaLoader();
            TableList tables = loader.GetTableList();
            HRCTable table = tables.GetTableName(Tools.HRCTestTableName);
            Assert.IsNotNull(table);
        }

        [Test, Ignore]
        public void GetSchema_Should_Be_Properly_Working()
        {
            HRCIS.SchemaLoader.SchemaLoader loader = new HRCIS.SchemaLoader.SchemaLoader();
            TableList tables = loader.GetTableList();
            HRCTable table = tables.GetTableName(Tools.HRCTestTableName);

            HRCSchema schema = loader.GetSchema(table);
            Assert.IsNotNull(schema);

            Assert.AreNotEqual(schema.Columns, 0);
        }

        //[Test]
        //public void GetTableList_Should_Be_Correct_SQLMOCK()
        //{
        //    var schemaLoaderStrategy = new Mock<ISchemaLoaderStrategy>();

        //    schemaLoaderStrategy.Setup(s => s.GetTableList())
        //        .Returns(() =>
        //            {
        //                return new TableList();
        //            });

        //    HRCIS.SchemaLoader.SchemaLoader loader = new HRCIS.SchemaLoader.SchemaLoader(schemaLoaderStrategy.Object);
        //    TableList tables = loader.GetTableList();
        //}

        [Test]
        public void SchemaColumns_Should_Be_Correct_ForSQL()
        {
            var sqlSchemaLoader = new SQLSchemaLoader();
            HRCIS.SchemaLoader.SchemaLoader loader = new HRCIS.SchemaLoader.SchemaLoader(sqlSchemaLoader);
            TableList tables = loader.GetTableList();
            HRCSchema testTable = loader.GetSchema(tables.GetTableName(Tools.HRCTestTableName));

            Assert.IsNotNull(testTable.Columns);

            HRCColumn Id = testTable.Columns.GetColumnByColumnName("Id");
            Assert.AreEqual(Id.ColumnDataType, DataType.INT);

            HRCColumn NVarCharColumn = testTable.Columns.GetColumnByColumnName("NVarCharColumn");
            Assert.AreEqual(NVarCharColumn.ColumnDataType, DataType.STRING);

            HRCColumn VarCharColumn = testTable.Columns.GetColumnByColumnName("VarCharColumn");
            Assert.AreEqual(VarCharColumn.ColumnDataType, DataType.STRING);

            HRCColumn BitColumn = testTable.Columns.GetColumnByColumnName("BitColumn");
            Assert.AreEqual(BitColumn.ColumnDataType, DataType.BOOLEAN);

            HRCColumn IntColumn = testTable.Columns.GetColumnByColumnName("IntColumn");
            Assert.AreEqual(IntColumn.ColumnDataType, DataType.INT);

            HRCColumn DateTimeColumn = testTable.Columns.GetColumnByColumnName("DateTimeColumn");
            Assert.AreEqual(DateTimeColumn.ColumnDataType, DataType.DATETIME);

            HRCColumn FloatColumn = testTable.Columns.GetColumnByColumnName("FloatColumn");
            Assert.AreEqual(FloatColumn.ColumnDataType, DataType.FLOAT);

            HRCColumn DecimalColumn = testTable.Columns.GetColumnByColumnName("DecimalColumn");
            Assert.AreEqual(DecimalColumn.ColumnDataType, DataType.DECIMAL);

            HRCColumn CharColumn = testTable.Columns.GetColumnByColumnName("CharColumn");
            Assert.AreEqual(CharColumn.ColumnDataType, DataType.Char);

            HRCColumn MoneyColumn = testTable.Columns.GetColumnByColumnName("MoneyColumn");
            Assert.AreEqual(MoneyColumn.ColumnDataType, DataType.Money);

            HRCColumn GuidColumn = testTable.Columns.GetColumnByColumnName("GuidColumn");
            Assert.AreEqual(GuidColumn.ColumnDataType, DataType.GUID);

            HRCColumn XmlColumn = testTable.Columns.GetColumnByColumnName("XmlColumn");
            Assert.AreEqual(XmlColumn.ColumnDataType, DataType.XML);

            HRCColumn DateColumn = testTable.Columns.GetColumnByColumnName("DateColumn");
            Assert.AreEqual(DateColumn.ColumnDataType, DataType.DATETIME);
        }
    }
}